<?php

/**
 * Product filter form.
 *
 * @package    jobeet
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: ProductFormFilter.class.php 7 2011-04-20 11:17:06Z Inoryy@gmail.com $
 */
class ProductFormFilter extends BaseProductFormFilter
{
  public function configure()
  {
  	$this->widgetSchema['name'] = new sfWidgetFormInput();
  	$this->validatorSchema['name'] = new sfValidatorPass(array('required' => false));
  	
	$this->widgetSchema['product_group'] = new sfWidgetFormSelectMany(array('choices' => 
		$this->getProductGroupChoices() ), array( 'size' => 3, 'style' => 'width:100px' ) );
	$this->validatorSchema['product_group'] = new sfValidatorPass(array('required' => false));
  	
  	  	
  }
  
  public function getProductGroupChoices(){
  	 
  	$result = array();

  	
  	foreach( Doctrine::getTable('ProductGroup')->findAll()  as $pg ){
  		if( $pg['title'] != 'root' )
  		$result[$pg['id']] = $pg['title'];
  	}
  	
  	return $result;
  				
	
  }
  
    protected function addNameColumnQuery(Doctrine_Query $query, $field, $values) {
    	if($values)
			$query->andWhere( 'r.Translation.name LIKE ?', "%${values}%");
			
    }
    
    protected function addProductGroupColumnQuery(Doctrine_Query $query, $field, $values) {
		if( $values )
			$query->innerJoin('r.ProductGroups pgs')
				->andWhereIn( 'pgs.group_id', $values );
			
    }
}
